﻿@Html.DevExpress().GridView(
            settings =>
            {
                settings.Name = "gvEditing";
                settings.KeyFieldName = "FDocId";
                settings.CallbackRouteValues = new { Controller = "Album", Action = "AlbumListPartial" };
                settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);


                settings.SettingsBehavior.AllowSort = false;
                settings.SettingsBehavior.AllowDragDrop = false;
                settings.SettingsBehavior.AllowSelectByRowClick = false;
                settings.SettingsLoadingPanel.Text = "数据读取中...";
                settings.SettingsBehavior.AllowClientEventsOnLoad = false;
                settings.SettingsBehavior.AllowFocusedRow = false;


                settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";


                settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
                settings.SettingsPager.FirstPageButton.Visible = true;
                settings.SettingsPager.LastPageButton.Visible = true;
                settings.SettingsPager.PageSize = ViewData["pageRowSize"] != null ? int.Parse(ViewData["pageRowSize"].ToString()) : 0;
                settings.SettingsPager.AlwaysShowPager = true;

                settings.CommandColumn.Visible = true;
                //settings.CommandColumn.ShowSelectCheckbox = true;
                settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Pixel(100);
                settings.CommandColumn.SetHeaderTemplateContent(c =>
                {
                    //Html.DevExpress().CheckBox(settingsCheckBox =>
                    //{
                    //    settingsCheckBox.Name = "cbSelectAll";
                    //    settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectAllRowsOnPage(); else {0}.UnselectAllRowsOnPage(); }}", settings.Name);

                    //    if (c.Grid.VisibleRowCount == 0)
                    //    {
                    //        settingsCheckBox.Enabled = false;

                    //    }
                    //    else
                    //    {
                    //        settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
                    //    }


                    //}).Render();

                    ViewContext.Writer.Write("相册");


                });




                int begin = 0;
                int step = 3;
                int end = begin + step;
                List<ElingOA6_Admin_DSJCJ.Model.Album> docList = (List<ElingOA6_Admin_DSJCJ.Model.Album>)Model;
                docList = docList.Where(c => null != c).ToList();
                int count = docList.Count;
                if (count < end)
                {
                    end = count;
                }


                settings.SetDataRowTemplateContent(c =>
                {
                    if (begin < count)
                    {
                        ViewContext.Writer.Write(
                        "<div style=\"padding:5px\">" +
                            "<table class=\"templateTable\">" +
                                "<tr>"
                            );

                        for (int i = begin; i < end; i++)
                        {
                            ElingOA6_Admin_DSJCJ.Model.Album doc = docList[i];

                            ViewContext.Writer.Write(
                                "<td width=\"33%\"><table>" +
                                "<tr><td>" +
                                "<img src='" + Url.Action("PhotoShow", "Album", new { albumId = doc.FAlbumId, t = DateTime.Now }) + "' width='165' height='98' onclick=\"javascript:window.location.href= rootPath + '/Admin/Album/PicList?albumId=" + doc.FAlbumId + "&albumClsNo=" + doc.FAlbumClsNo + "';\" style='cursor:pointer' />" +
                                "</td></tr>" +
                                "<tr><td><div style='width:165px;white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow:hidden;' title='" + doc.FFileName + "'>" +
                                doc.FFileName +
                                "</div></td></tr>"
                             );

                            ViewContext.Writer.Write("<tr><td>");
                            ViewContext.Writer.Write("<span onclick=\"edit('" + doc.FAlbumId + "','" + doc.FAlbumClsNo + "')\" style='cursor:pointer'>[编辑]</span> <span onclick=\"del('" + doc.FAlbumId + "','" + doc.FAlbumClsNo + "')\" style='cursor:pointer;color:red'>[删除]</span>");
                            ViewContext.Writer.Write("</td></tr>");
                            
                            ViewContext.Writer.Write("</table></td>");
                        }


                        if (end == count)
                        {
                            for (int l = 0; l < (3 - (end - begin)); l++)
                            {
                                ViewContext.Writer.Write(
                                "<td width=\"33%\"></td>"
                             );


                            }
                        }



                        ViewContext.Writer.Write(
                            "</tr></table></div>"
                       );


                        begin = end;
                        end = begin + step;
                        if (end > count)
                        {
                            end = count;
                        }

                    }

                });


                settings.PageIndexChanged = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    grid.Selection.UnselectAll();
                };

                settings.DataBound = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    if (ViewData["pageIndex"] != null)
                    {
                        if (ViewData["pageIndex"].ToString() != "")
                        {
                            if (grid.PageCount < int.Parse(ViewData["pageIndex"].ToString()))
                            {
                                grid.PageIndex = 0;
                            }
                            else
                            {
                                grid.PageIndex = int.Parse(ViewData["pageIndex"].ToString());
                            }
                        }
                    }
                };


            }).Bind(Model).GetHtml()
